package com.crm.system.service.impl.sendRoyaltyManager;

import com.crm.common.model.DhPageInfo;
import com.crm.model.vo.sendRoyaltyManager.OrderSendRoyaltyLogVO;
import com.crm.service.sendRoyaltyManager.SendRoyaltyLogDbService;
import com.crm.system.service.sendRoyaltyManager.SendRoyaltyLogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author:chaifuyou
 * @Date: 2021/5/27 10:41
 */
@Service
public class SendRoyaltyLogServiceImpl implements SendRoyaltyLogService {

    @Autowired
    private SendRoyaltyLogDbService sendRoyaltyLogDbService;
    
    /**
     * 分页查询提成发放修改记录
     * @param orderId
     * @param pageIndex
     * @param pageSize
     * @param sortName
     * @param sortOrder
     * @return
     */
    @Override
    public DhPageInfo<OrderSendRoyaltyLogVO> selectSendRoyaltyLogList(String orderId, Integer pageIndex, Integer pageSize, String sortName, String sortOrder) {
        if (pageIndex != null && pageSize != null) {
            PageHelper.startPage(pageIndex, pageSize);
        }
        //排序
        StringBuilder order = new StringBuilder();
        if(!StringUtils.isBlank(sortName)&&!StringUtils.isBlank(sortOrder)){
            switch(sortName){
                case "createTm":
                {
                    order.append("create_tm ").append(sortOrder);//创建时间
                }
                break;
                default:
                    break;
            }
        }
        List<OrderSendRoyaltyLogVO> retustList=sendRoyaltyLogDbService.selectSendRoyaltyLogList(orderId,order.toString());
        PageInfo<OrderSendRoyaltyLogVO> page =new PageInfo(retustList);
        return new DhPageInfo<OrderSendRoyaltyLogVO>(page,retustList);
    }
}
